package part18;

import java.io.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

/**
 * @author wcj
 * @Date 2021/6/4 17:18
 * @Version 1.0
 */
public class Part1831 {

    /**
     * 压缩的使用方式非常简单
     * 就是将GzipInputStream包装成为BufferedInputStream或者将GzipOutputStream包装成为BufferedOutputStream即可
     *
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new FileReader(new File("./src/part18/Part1831.java")));
        BufferedOutputStream out = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream("test.gz")));
        System.out.println("Writing file:");
        int c;
        while ((c = in.read()) != -1) {
            out.write(c);
        }
        in.close();
        out.close();
        System.out.println("Reading file:");
        BufferedReader inGz = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(new File("test.gz")))));
        String s;
        while ((s = inGz.readLine()) != null) {
            System.out.println(s);
        }
    }
}
